<template>
	<view class="container-robot" style="background: url(/static/imgbgc.png) no-repeat; background-size: 100%">
		<view class="main">
			<view class="item-robot flex" v-for="(item,index) in list" :key="item.id">
				<view class="lt">
					<image :src="$fun.imgUrl(item.image)" mode=""></image>
				</view>
				<view class="rt">
					<view class="title">{{item.name}}</view>
					<view class="">{{$t('vnode.name22')}}：{{item.balance}}{{$t('vnode.name23')}}</view>
					<view class="flex">
						促销月化:{{item.release}}%<text class="through">月化:{{item.old_release}}%</text>
					</view>
					<view class="flex-between">
						<text class="price">{{item.money}}</text>
						<view class="">
							<u-button type="primary" :text="$t('vnode.name14')" shape="circle" style="width: 160rpx;"
								color="#00A3FF" size="small" @click="handlePay(item)"></u-button>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-popup :show="show" :round="10" @close="close" closeable>
			<view class="popup-box">
				<view class="title">
					{{$t('vnode.name15')}}
				</view>
				<view class="input flex">
					<view class="">
						{{$t('vnode.name16')}}:
					</view>
					<input type="text" :disabled="disabled" v-model="money" :placeholder="$t('vnode.name17')" />
				</view>
				<!-- <view class="text">
					{{$t('vnode.name18')}}：{{model.min_money}}~{{model.mx_money}}
				</view> -->
				<view class="btn">
					<u-button type="primary" :text="$t('vnode.name19')" shape="circle" @click="handleNext"></u-button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				show: false,
				model: {},
				money: '',
				id: 0,
				listitem: '',
				disabled: true,
				type: ''
			};
		},
		onLoad(option) {
			this.id = option.id
			this.type = option.type
			this.disabled = option.id ? false : true
			this.getProductList()
		},
		methods: {
			// 获取机器人列表
			async getProductList() {
				const res = await this.$fun.ajax.post('product/productList')
				this.list = res.data
				res.data.map((item) => {
					item.release = (item.release * 100).toFixed(2)
					item.old_release = (item.old_release * 100).toFixed(2)
					if (item.id == this.id) {
						this.listitem = item
						this.handlePay(item)
					}
				})
			},
			close() {
				this.show = false
				this.model = {}
				this.money = ''
			},
			handleNext() {
				if (!this.money) return this.$fun.msg(this.$t('vnode.name20'))
				// if (!(+this.money >= +this.model.min_money && +this.money <= +this.model.mx_money)) {
				// 	return this.$fun.msg(this.$t('vnode.name21'))
				// }
				if (this.money < 100) {
					this.$fun.msg('金额不能小于100')
					return;
				}
				this.$fun.jump(
					`/pageC/robotPay/robotPay?id=${this.model.id}&url=${this.model.image}&money=${this.money}&name=${this.model.name}&type=${this.type}`
				)
			},
			async handlePay(val) {
				this.show = true
				this.model = val
				this.money = val.money
				// this.$fun.jump(`/pageC/robotPay/robotPay?id=${val.id}&url=${val.image}&money=${val.money}&name=${val.name}`)
				// const res = await this.$fun.ajax.post('product/productList')
			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
	}

	.container-robot {
		height: 100%;

		.popup-box {
			height: 500rpx;
			padding: 0 30rpx;

			.title {
				text-align: center;
				padding: 20rpx 0;
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				font-size: 32rpx;
				color: #232323;

			}

			.input {
				margin-top: 80rpx;
				padding: 20rpx 0;
				border-bottom: 1rpx solid #d9d9d9;
			}

			.text {
				font-size: 24rpx;
				color: #b9b9b9;
			}

			.btn {
				margin-top: 80rpx;
			}
		}

		.main {
			padding: 30rpx;

			.item-robot {
				height: 190rpx;
				background-color: rgba(68, 78, 99, 0.7);
				border-radius: 20rpx;
				padding: 10rpx 30rpx;
				margin: 20rpx 0;

				.lt {
					width: 170rpx;
					height: 100%;
					margin-right: 20rpx;

				}

				.rt {
					flex: 1;

					& view:nth-child(1) {
						font-family: PingFang SC, PingFang SC;
						font-weight: bold;
						font-size: 32rpx;
						color: #FFFFFF;
						line-height: 38rpx;
					}

					& view:nth-child(2),
					& view:nth-child(3) {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 24rpx;
						color: #b8b8b8;

						.through {
							font-weight: 400;
							font-size: 24rpx;
							color: #b8b8b8;
							text-decoration: line-through;
							margin-left: 10rpx;
						}
					}

					.price {
						font-family: DIN, DIN;
						font-weight: bold;
						font-size: 28rpx;
						color: #FF4201;
						line-height: 56rpx;
					}
				}
			}
		}
	}
</style>